#安装规三方库
#只安装release的库
#此宏会自动找到标准包目录的库文件
#自动移除Debug的动态库*d.dll/*dd.dll
macro(INSTALL_3RD_PKG pkg_name pkg_root_dir)
    if(WIN32)
		#========bin======
		install(CODE "MESSAGE(\"install pkg dlls...\")")
    	file(GLOB ALL_DLLS ${pkg_root_dir}/bin/*.dll)
		message(NOTICE "^^^^${pkg_name} Install Dlls:\n  ${ALL_DLLS}")
		COMMON_GET_RELEASE_RUNTIME_FILES(ALL_DLLS REL_DLLS)
      	install(FILES ${REL_DLLS} 
				DESTINATION bin 
				CONFIGURATIONS Release RelWithDebInfo 
				PERMISSIONS
          			OWNER_READ OWNER_WRITE OWNER_EXECUTE 
				GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE 
				COMPONENT Runtime
			)
   else(WIN32)
		install(CODE "MESSAGE(\"install pkg dlls...\")")
      	file(GLOB REL_SOS ${pkg_root_dir}/lib64/*.so*)
		file(GLOB REL_SOS_1 ${pkg_root_dir}/lib/*.so)
		file(GLOB REL_SOS_2 ${pkg_root_dir}/lib/*.so*)
      	install(FILES ${REL_SOS} ${REL_SOS_1} ${REL_SOS_2}
				DESTINATION bin 
				PERMISSIONS
          		OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE 
				COMPONENT Runtime
			)
   endif(WIN32)
endmacro()

#规范PKG包的全局变量
#用于后期生成调试环境使用
macro(MAKE_3RD_PKG_RUNTIME pkg_name pkg_root)
	if(WIN32)
		set_property(GLOBAL PROPERTY 
			${pkg_name}_BINDIR_RELEASE 
			${pkg_root}/bin)
		set_property(GLOBAL PROPERTY 
			${pkg_name}_BINDIR_DEBUG 
			${pkg_root}/bin)
	else()
		set_property(GLOBAL PROPERTY 
			${pkg_name}_BINDIR_RELEASE 
				${pkg_root}/bin)
		set_property(GLOBAL PROPERTY 
			${pkg_name}_BINDIR_DEBUG 
				${pkg_root}/bin)
	endif()
endmacro()

macro(SEARCH_3RD_MAYBE_PATH out_dir)
	set(${out_dir} "")
	foreach(_pth ${ARGN})
		message(STATUS "----Detect: ${_pth}")
		if(EXISTS ${_pth})
			set(${out_dir} ${_pth})
			break()
		endif()
	endforeach()

	message(STATUS "====Detected: ${out_dir}=${${out_dir}}")
	IF(NOT EXISTS ${${out_dir}})
		message(FATAL_ERROR "No Find 3RD Root Path...${${out_dir}}")
	ENDIF()
endmacro()

macro(SEARCH_3RD_MAYBE_PATH2 pkg_name out_dir)
	set(${out_dir} "")
	foreach(_pth ${ARGN})
		message(STATUS "----Pre Detect Pkg[${pkg_name}] : ${_pth}")
		if(EXISTS ${_pth})
			set(${out_dir} ${_pth})
			break()
		endif()
	endforeach()

	#message(STATUS "====Detected: ${out_dir}=${${out_dir}}")
	IF(NOT EXISTS ${${out_dir}})
		message(FATAL_ERROR "No Find 3RD Path Of Package [${pkg_name}]: ${${out_dir}}")
	ENDIF()
endmacro()

macro(GET_THIRD_PARTY_PACKAGE_DIR_NAME packageName out_package_dir_name)
	#message("GCC version: ${CMAKE_CXX_COMPILER_VERSION}")
	#message("System name: ${CMAKE_SYSTEM_NAME}")
	#message("CMAKE_SYSTEM_PROCESSOR version: ${CMAKE_SYSTEM_PROCESSOR}")
	STRING(TOLOWER ${CMAKE_SYSTEM_NAME} system_name)
	# STRING(CONCAT pkg_name ${packageName} "-" 
	# 	${system_name} "-"
	# 	"gcc" ${CMAKE_CXX_COMPILER_VERSION} "-"
	# 	${CMAKE_SYSTEM_PROCESSOR})
	STRING(CONCAT pkg_name ${packageName} "-" 
		${system_name} "-"
		${CMAKE_SYSTEM_PROCESSOR})
	set(${out_package_dir_name} ${pkg_name})
	#message(FATAL_ERROR "No Find Package Dir Name...${pkg_name}")
endmacro()
